package jp.co.jalinfotec.sxt.entity;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

/** Order Entity */
@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class OrderEntity {

	/** Internal key */
	@PrimaryKey
	@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
	private Key internalKey;
	
	/**
	 * [Setter]Internal key
	 * @param internalKey Internal key
	 */
	public void setInternalKey(Key internalKey) { this.internalKey = internalKey; }

	/**
	 * [Getter]Internal key
	 * @return Internal key
	 */
	public Key getInternalKey() { return this.internalKey; }
	
	/** User ID */
	private String userId;
	
	/**
	 * [Setter]User ID
	 * @param userId User ID
	 */
	public void setUserId(String userId) { this.userId = userId; }

	/**
	 * [Getter]User ID
	 * @return User ID
	 */
	public String getUserId() { return this.userId; }
	
	/** Order Title */
	private String title;
	
	/**
	 * [Setter]Order Title
	 * @param title Order Title
	 */
	public void setTitle(String title) { this.title = title; }

	/**
	 * [Getter]Order Title
	 * @return Order Title
	 */
	public String getTitle() { return this.title; }
	
	/** Order Type */
	private String type;
	
	/**
	 * [Setter]Order Type
	 * @param type Order Type
	 */
	public void setType(String type) { this.type = type; }

	/**
	 * [Getter]Order Type
	 * @return Order Type
	 */
	public String getType() { return this.type; }
	
	/** Order Target Date */
	private Date targetDate;
	
	/**
	 * [Setter]Order Target Date
	 * @param targetDate Order Target Date
	 */
	public void setTargetDate(Date targetDate) { this.targetDate = targetDate; }

	/**
	 * [Getter]Order Target Date
	 * @return Order Target Date
	 */
	public Date getTargetDate() { return this.targetDate; }
	
	/** Default Constructor */
	public OrderEntity(){}
	
	/**
	 *Create internal key
	 * @param userId User ID
	 * @param orderTargetDate Order Target Date
	 * @return Key object
	 */
	public static Key createKey(String userId, Date orderTargetDate){
		return new KeyFactory.Builder(
				OrderEntity.class.getSimpleName(),
				OrderEntity.class.getSimpleName()
					+ userId
					+ orderTargetDate.toString()).getKey();
	}
}
